package com.hxd.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.hxd.common.Result;
import com.hxd.common.utils.ServletUtils;
import com.hxd.pojo.LoginVO;
import com.hxd.service.SysUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags="登录")
@RestController
public class LoginController {
	
	protected final Logger logger = LoggerFactory.getLogger(LoginController.class);
	
	@Autowired
	private SysUserService sysUserService;
	
	@PostMapping("/login")
	@ApiOperation(value = "用户登录")
	public Result login(@Validated @RequestBody LoginVO loginVO) {
		logger.debug("debug log");
		logger.error("error log");
		return Result.success(sysUserService.login(loginVO));
	}
	
	@PostMapping("/logout")
	@ApiOperation(value = "用户注销 清除缓存")
	public Result logout(HttpServletRequest request) {
		sysUserService.logout(ServletUtils.getUserId());
		return Result.success();
	}
	
}
